{extend name="../template/admin/head.html"}
{block name="title"}
添加新页面_{__block__}
{/block}
{block name="content"}
<blockquote class="layui-elem-quote title" style="margin-left:10px;margin-top:10px;"><h2>添加页面</h2></blockquote>
<form class="layui-form" >
  <div class="layui-form-item">
    <label class="layui-form-label">页面标题</label>
    <div class="layui-input-block">
      <input type="text" class="layui-input newsName" lay-verify="required" placeholder="请输入文章标题" id="actitle">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">页面内容</label>
    <div class="layui-input-block">
      <div id="editor">
      </div>
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn kit-login-btn" lay-submit="submit" lay-filter="addNews" id="addNews">立即发布</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>

{/block}
{block name="jssrc"}
<script type="text/javascript" src="__public__/wangEditor.min.js"></script>
<script type="text/javascript">
  layui.use(['form', 'layedit', 'laydate'], function() {
    var form = layui.form,
    layer = layui.layer,
    layedit = layui.layedit,
    laydate = layui.laydate;
});
//JavaScript代码区域
layui.use('element', function(){
  var element = layui.element;
}); 
layui.use(['form','layedit'], function(){
  var form = layui.form;
  var layedit = layui.layedit;
  //创建编辑器
  var E = window.wangEditor
  var editor = new E('#editor')
  // 配置服务器端地址
  editor.customConfig.uploadImgServer = "{:URL('Artice/imgupload')}";
  editor.customConfig.uploadFileName = 'images';
  editor.customConfig.debug = true
  editor.create()
  //新增
form.on('submit(addNews)', function(data){
    title = $('#actitle').val();
    author  = '';
    cid     = 'no';
    keyword = 'no';
    abstract= 'no';
    content = editor.txt.html();
    type = 'page';
    //定义全局变量
    var top = '0';
    var show = '1';
    if (title != "" && content != "") {
       form.render(); //更新全部
       $.ajax({
          type:"post",
          url:"{:URL('Artice/acadd')}",
          dataType:"json",
          data:{title:title,author:author,cid:cid,keyword:keyword,abstract:abstract,content:content,top:top,show:show,type:type},
            beforeSend: function () {
            // 禁用按钮防止重复提交
            $("#addNews").attr({"disabled":"disabled"});
            $("#addNews").addClass("layui-btn-disabled");
            $("#addNews").html("发布中...");
            layer.load(1);
            },
           error: function (XmlHttpRequest, textStatus, errorThrown) {
              if (XmlHttpRequest.responseText != "") {
                  layer.msg('提交失败，请稍后尝试！');
                  layer.closeAll('loading');
                  $("#addNews").removeClass("layui-btn-disabled");
                  $("#addNews").removeAttr("disabled");  
                  $("#addNews").html("立即发布");
              }
          },
          success:function(data){
            if (data.result == "1") {
              layer.closeAll('loading');
              layer.msg(data.msg);
              setTimeout(function(){
                location.href=data.url;
              },1000);
            }else if(data.result = "2"){
              layer.closeAll('loading');
              layer.msg(data.msg);
            }
          }
        });
    }else{
      layer.msg('标题和内容不能为空');
    }
    return false;
  });
});
</script>
{/block}